package com.samp.base.jce.type01;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;

public class MD5Demo {

    public static byte[] encrypt(String info) throws NoSuchAlgorithmException{
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        byte[] srcBytes = info.getBytes();
        md5.update(srcBytes);
        byte[] resultBytes = md5.digest();
        return resultBytes;
    }

    public static void main(String[] args) {
        String message = "张三,ad e!!***\\/";
        String message2 = "..";
        try{
            byte[] resultBytes = encrypt(message);
            String result = Base64.getEncoder().encodeToString(resultBytes);
            System.out.println("明文："+message);
            System.out.println("密文："+result);

            resultBytes = encrypt(message2);
            result = Base64.getEncoder().encodeToString(resultBytes);
            System.out.println("明文："+message2);
            System.out.println("密文："+result);

        }catch (NoSuchAlgorithmException e){
            e.printStackTrace();
        }
    }
}
